# Joy -- implementation of the Joy programming language
# Copyright © 2017 Eric Bavier <bavier@member.fsf.org>
#
# Joy is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# Joy is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Joy.  If not, see <http://www.gnu.org/licenses/>.

AT_BANNER([Joy])

AT_SETUP([version])
AT_CHECK([joy --version],[0],[stdout])
AT_CHECK([$GREP --quiet "]AT_PACKAGE_VERSION[" stdout])
AT_CLEANUP

AT_SETUP([help])
AT_CHECK([joy --help],[0],[stdout])
AT_CHECK([$GREP --quiet "Usage:" stdout])
AT_CHECK([$GREP --quiet -- "--help" stdout])
AT_CHECK([$GREP --quiet -- "--version" stdout])
AT_CLEANUP

AT_SETUP([script])
AT_DATA([foo.joy],
["base" include
"Hello, world!" putchars
])
AT_CHECK([joy foo.joy],[0],[stdout])
AT_CHECK([$GREP --quiet 'Hello, world!' stdout])
AT_CLEANUP

AT_SETUP([multiple scripts])
AT_DATA([foo.joy], [3 2 1 +
])
AT_DATA([bar.joy],
["base" include
"product: " putchars
* .
])
AT_CHECK([joy foo.joy bar.joy],[0],[stdout])
AT_CHECK([$GREP --quiet "product: 9" stdout])
AT_CLEANUP

AT_SETUP([include dirs])
AT_CHECK([mkdir -p dir])
AT_DATA([dir/foo.joy],
["base" include
"hello" cdr 'H putch putchars
])
AT_CHECK([joy -I dir foo.joy],[0],[stdout])
AT_CHECK([$GREP --quiet "Hello" stdout])
AT_CLEANUP

AT_SETUP([stack init])
AT_DATA([foo.joy],[+ .
])
AT_CHECK([joy foo.joy -S 1 2],[0],[stdout])
AT_CHECK([$GREP --quiet "3" stdout])
AT_CHECK([joy foo.joy --stack 1 2 5],[0],[stdout])
AT_CHECK([$GREP --quiet "7" stdout])
AT_CLEANUP